package net.oschina.app.viewpagerfragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import net.oschina.app.R;
import net.oschina.app.adapter.NewsPagerAdapter;
import net.oschina.app.viewpagerfragment.tweetDetailFragment.HotTweetFragment;
import net.oschina.app.viewpagerfragment.tweetDetailFragment.MyTweetFragment;
import net.oschina.app.viewpagerfragment.tweetDetailFragment.NewsTweetFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by foty on 2017/4/1.
 * ?
 */

public class TweetFragment extends Fragment{
    private List<Fragment> mFList;
    private List<String> mTList;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
       View view = inflater.inflate(R.layout.tweet_fragment,container,false);
        ViewPager viewPager = (ViewPager) view.findViewById(R.id.tweet_fragment_viewPager);
        TabLayout tabLayout= (TabLayout) view.findViewById(R.id.tweet_fragment_tab);
        HotTweetFragment hotTweetFragment = new HotTweetFragment();
        MyTweetFragment myTweetFragment = new MyTweetFragment();
        NewsTweetFragment newsTweetFragment =  new NewsTweetFragment();
        mFList = new ArrayList<>();
        mTList = new ArrayList<>();
        mFList.add(newsTweetFragment);
        mFList.add(hotTweetFragment);
        mFList.add(myTweetFragment);

        mTList.add("最新动弹");
        mTList.add("热门动弹");
        mTList.add("我的动弹");

        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.addTab(tabLayout.newTab().setText(mTList.get(0)));
        tabLayout.addTab(tabLayout.newTab().setText(mTList.get(1)));
        tabLayout.addTab(tabLayout.newTab().setText(mTList.get(2)));

        viewPager.setAdapter(new NewsPagerAdapter(getChildFragmentManager(), mFList,
                mTList));
        tabLayout.setupWithViewPager(viewPager);
        return view;
    }
}
